<template>
  <div>
    <!-- 面包屑导航区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
			<el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
			<el-breadcrumb-item>数据统计</el-breadcrumb-item>
			<el-breadcrumb-item>数据报表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片区域 -->
    <el-card>
      <!-- 2.为echarts准备一个有宽高的dom -->
      <div id="main" style="width: 600px; height: 400px"></div>
    </el-card>
  </div>
</template>

<script>
// 1.导入echarts
import * as echarts from 'echarts'
export default {
  name:'Report',
  data() {
    return {
      
    }
  },
  created(){},
  async mounted(){
    // 3.基于准备好dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('main'))   

    // 4.准备图表的配置和数据
    var option = {
      title:{
        text:'Echarts 图表'
      },
      tooltip:{},
      legend:{
        data:['箱量']
      },
      xAxis:{
        data:['衣服','鞋子','裤子']
      },
      yAxis:{},
      series:[{
        name:'销量',
        type:'bar',
        data:[5,16,20,10,20]
      }]
    }

    const {data:res} = await this.$http.get('reports/type/1')
    //console.log(res)
    if(res.meta.status !== 200) return this.$message.error('获取折线图数据失败')
    // 合并两个数据
    const result = {...option, ...res.data}

    // 5.图表形式展示数据
    myChart.setOption(result)
  },
}
</script>

<style lang="less" scoped>
div /deep/ .el-card{
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  margin-top: 20px;
}
</style>